package io.kiki.stack.http.feign.error;

import feign.Response;

import java.lang.annotation.*;

@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface ErrorHandling {
    ErrorCodes[] codeSpecific() default {};

    Class<? extends Exception> defaultException() default NO_DEFAULT.class;

    final class NO_DEFAULT extends Exception {
        @FeignExceptionConstructor
        public NO_DEFAULT(@ResponseBody Response response) {
            super("Endpoint responded with " + response.status() + ", reason: " + response.reason());
        }
    }
}
